<template>
  <div class="header">
    <div  class="user_info" 
          @click='dropMenu()' 
          v-bind:class='{user_info_select:isSelect}'>
          <img src="../assets/watermeLonMan.jpg" alt="西瓜大侠">
          {{user_info}}
    </div>
    <div  class="user_operate" 
          v-show='user_operate'>
          <div class="user_operate_top">
              <li>
                <img src="../assets/watermeLonMan.jpg" alt="西瓜大侠">
              </li>
              <p>{{user_info}}</p>
              <p>{{time}}</p>
          </div>
          <div class="user_operate_bottom">
              <button class='user_logout'>退出登录</button>
          </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'header',
  data () {
    return {
      user_info: 'admin',
      date:new Date(),
      isSelect:false,
      user_operate:false
    }
  },
  computed:{
    time() {
      let day = this.date.getDate(),
          month = this.date.getMonth()+1,
          year = this.date.getFullYear(),
          time = year+'/'+month+'/'+day;
      return time;
    }
  },
  methods:{
    dropMenu() {
      if(!this.isSelect){
        this.isSelect = true;
        this.user_operate = true;
      }else {
        this.isSelect = false;
        this.user_operate = false;
      }
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
  .header{
    height: 50px;
    background-color: #3c8dbc;
    padding-left: 160px;
    text-align: center;
    color: #fff;
    position: relative;
  }
  .user_info{
    width: 120px;
    float: right;
    line-height: 50px;
  }
  .user_info:hover{
    background-color: #367fa9;
    cursor: pointer;
  }

  .user_info img{
    height: 30px;
    width: auto;
    margin-top: 10px;
    float: left;
    margin-left: 10px;
    border-radius: 100%;
  }

  .user_info_select{
    background: #367fa9;
  }

  .user_operate{
    width: 280px;
    border: 1px solid #ddd;
    position: absolute;
    right: 0;
    top: 50px;
    z-index: 1000;
  }
  .user_operate_top{
    height: 175px;
    background-color: #3c8dbc;
  }
  .user_operate_top li{
    list-style: none;
    width: 80px;
    height: 80px;
    margin: auto;
    padding-top: 15px;
    text-align: center;
  }
  .user_operate_top p{
    margin: 0;
    padding: 10px 0 0;
  }
  .user_operate_top li img{
    width: 100%;
    height: 100%;
    border-radius: 100%;
    border: 2px solid #7bc0e8;
  }
  .user_operate_bottom{
    background: #f9f9f9;
    overflow: hidden;
  }
  .user_logout{
    float: right;
    margin: 15px 15px 15px 0;
    background: #eee;
    border: none;
    padding: 8px 12px;
    font-size: 14px;
    transition: all 0.2s;
    cursor: pointer;
    border: 1px solid #d2d2d2;
  }
  .user_logout:hover{
    background: #d2d2d2;
    transition: all 0.2s;
  }
</style>
